// base.controller.ts
import { Request, Response } from "express";
import BaseServer from "./base.service";
import SearchDto from "../dtos/search.dto";

export default class BaseController<V> {
  protected service: BaseServer<V>;
  async getList<D extends SearchDto>(req: Request, res: Response) {
    console.log("BaseController-getList");
    const dto: D = {
      ...req.body,
      ...req.query,
      ...req.params,
    };
    const models = await this.service.getBasePageList<D>(dto);
    res.json(models);
  }
  add<D>(req: Request, res: Response): void {
    const dto: D = req.body;
    console.log("BaseController-add", dto);
    this.service.addBaseServer(dto);
    res.json({
      status: 0,
      msg: "操作成功",
    });
  }
}
